package logic

import (
	"context"
	"fmt"
	"gorm.io/gorm"
	"hr_srv/hr_srv"
	"hr_srv/internal/svc"
	"hr_srv/models"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateLogic) Update(in *hr_srv.UpdateRequest) (*hr_srv.UpdateResponse, error) {
	// todo: add your logic here and delete this line
	if models.DB.Updates(&models.User{
		Model: gorm.Model{
			ID: uint(in.UserId),
		},
		Phone:    "",
		Password: in.Password,
	}).Error != nil {
		return &hr_srv.UpdateResponse{}, fmt.Errorf("服务器繁忙")
	}
	return &hr_srv.UpdateResponse{}, nil
}
